package cn.wolfcode.crm.query;

import lombok.Getter;

import java.util.List;

//封装页面上用户需要的数据
@Getter
public class PageResult<T> {
    //查询出来
    private List<T> list;//结果集
    private int totalCount;//总条数
    //用户传递
    private int currentPage;//当前页
    private int pageSize;//页面大小
    //计算出来
    private int prevPage;//上一页
    private int nextPage;//下一业
    private int totalPage;//总页数

    public PageResult(List<T> list, int totalCount, int currentPage, int pageSize) {
        this.list = list;
        this.totalCount = totalCount;
        this.currentPage = currentPage;
        this.pageSize = pageSize;

        if (totalCount <= pageSize) {
            totalPage = 1;
            prevPage = 1;
            nextPage = 1;
            return;
        }

        this.totalPage = this.totalCount % this.pageSize == 0 ? this.totalCount / this.pageSize : this.totalCount / this.pageSize + 1;
        this.prevPage = this.currentPage - 1 >= 1 ? this.currentPage - 1 : 1;
        this.nextPage = this.currentPage + 1 <= this.totalPage ? this.currentPage + 1 : this.totalPage;
    }
}
